import time
import unittest
from common.open_browser import open_browser
from page.receiving_address_page import ReceivingAddress
from page.login_page import LoginPage
from common.base import Base, By


class ReceivingTestCase(unittest.TestCase):
    # 前大夹具
    @classmethod
    def setUpClass(cls) -> None:
        # 打开浏览器
        driver = open_browser()
        driver.maximize_window()
        # 创建ReceivingAddress对象
        cls.receiving = ReceivingAddress(driver)
        cls.login = LoginPage(driver)

    def test1_receiving(self):
        # 请求网址
        self.receiving.get('http://172.16.140.48/ecshop/user.php')
        # 输入登录信息
        self.login.input_username('wlyou')
        self.login.input_password('123456')
        self.login.input_remember()
        self.login.input_submit()
        # 点击用户中心
        time.sleep(2)
        self.receiving.click((By.LINK_TEXT, '用户中心'))
        # 点击收货地址
        time.sleep(2)
        self.receiving.click((By.XPATH, '/html/body/div[6]/div[1]/div/div/div/div/a[4]'))
        # 收货地址操作
        # 配送区域
        # time.sleep(2)
        self.receiving.input_country('中国')
        time.sleep(1)
        self.receiving.input_province('湖北省')
        time.sleep(1)
        self.receiving.input_city('咸宁市')
        time.sleep(1)
        self.receiving.input_district('赤壁市')
        # 收货人
        time.sleep(1)
        self.receiving.input_consignee('xjf')
        # 电子邮件地址
        time.sleep(1)
        self.receiving.input_email('597001831@qq.com')
        # 收货地址
        self.receiving.input_address('源码时代')
        # 邮政编码
        self.receiving.input_zip_code('430073')
        # 电话号码
        self.receiving.input_phone('17671765961')
        # 点击新增收货地址按键
        self.receiving.input_submit()

    # 后大夹具
    @classmethod
    def tearDownClass(cls) -> None:
        # 关闭浏览器
        time.sleep(5)
        cls.receiving.quit()


if __name__ == '__main__':
    unittest.main(verbosity=2)